package com.chamber.common.handler;

import com.chamber.common.constant.HttpStatus;
import com.chamber.common.core.domain.AjaxResult;
import com.chamber.common.core.text.Convert;
import com.chamber.common.exception.DemoModeException;
import com.chamber.common.exception.ServiceException;
import com.chamber.common.exception.base.BaseException;
import com.chamber.common.exception.business.PasswordOrAccountException;
import com.chamber.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingPathVariableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理器
 *
 * @author chamber
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
//    /**
//     * 基础的异常处理器
//     * @param baseException
//     * @return
//     */
//    @ExceptionHandler(BaseException.class)
//    public AjaxResult exceptionHandler(BaseException baseException) {
//        log.error("异常信息：{}", baseException.getMessage());
//        return AjaxResult.error(baseException.getMessage());
//    }

    /**
     * 账号或密码错误
     * @param passwordOrAccountException
     * @return
     */
    @ExceptionHandler(PasswordOrAccountException.class)
    public AjaxResult exceptionHandler(PasswordOrAccountException passwordOrAccountException) {
        log.error("异常{}", passwordOrAccountException.getMessage());
        return AjaxResult.error(passwordOrAccountException.getMessage());
    }

}
